<!-- 2020年2月17日18:18:53 完成 -->
<template>
	<view>
		<view class="edgeInsetTop"></view>
		<view style="padding: 20rpx 35rpx;height: 38px;background-color: #ffc8b4;font-size: small;">
			<!-- <image src="/static/images/user/gantan.png" style="width: 40rpx;height: 40rpx;"></image> -->
			<text style="color: crimson;">请正确填写以下申请信息</text>
		</view>
		<view class="cu-form-group" v-show="addressType">
			<view class="title">姓名</view>
			<input type="text" placeholder="请输入真实姓名" v-model="addressData.name"></input>
		</view>
		<view class="cu-form-group" v-show="addressType">
			<view class="title">联系电话</view>
			<input type="number" placeholder="请输入联系电话" maxlength="11" v-model="addressData.mobile"></input>
		</view>
		<view style="background-color: white;">
		<view  class="cu-form-group" v-show="addressType" style="margin-top: 20rpx;">
			<view class="title">身份证照片</view>
		
		</view>
		<view style="text-align: center;
    background-color: white;" @tap="chooseImage(1)">
			
				<image :src="image1" 
				mode="widthFix" style="width: 250px;height: 150px;"	></image>
	
			<text style="font-weight: 600;display: block;">上传身份证人像面</text>
		</view>
		<view style="text-align: center;
		background-color: white;margin-top: 40rpx;" @tap="chooseImage(2)">
			<image :src="image2" 
				mode="widthFix" style="width: 250px;height: 150px;">
			</image>
			<text style="font-weight: 600;display: block;">上传身份证国徽面</text>
		</view>
			<!-- <view style="color: #323232;">我已阅读并同意<u--text mode="link" text="《经纪人协议》" href="https://www.uviewui.com" ></u--text></view> -->
		</view>
			
	
		<!-- 1.0.5升级 -->
		<!-- 1.0.6升级 -->
		<view class="padding-bj flex flex-direction margin-top" v-show="addressType">
			<button @tap="confirm" class="cu-btn wanl-bg-orange lg">提交</button>
		</view>
		<!-- <wanl-address ref='wanlAddress' @selectAddress="successSelectAddress"></wanl-address> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressData: {
					name: '',
					mobile: '',
				},
				addressList: {
					location: '',
					adcode: '',
					tips: {}
				},
				image1:'https://1miyc.com/assets/img/zhengmian.png',
				image2:'https://1miyc.com/assets/img/fanmian.png',
				fileList1: [],
				fileList2: [],
				addressType: true
			}
		},
		onLoad(option) {

		},
		onNavigationBarButtonTap() {
			this.confirm()
		},
		methods: {
			chooseImage(type) {
				uni.chooseImage({
					count: 1, // 默认9
					sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: res => {
					
						// 设置url的值，显示控件
						
						// 上传图片
						this.$api.get({
							url: '/wanlshop/common/uploadData',
							success: updata => {
								this.$api.upload({
									url: updata.uploadurl,
									filePath: res.tempFilePaths[0],
									name: 'file',
									formData: updata.storage == 'local' ? null : updata.multipart,
									success: res => {
										if(type == 1){
											this.image1 = res.fullurl
										}else{
											this.image2 = res.fullurl
										}
									
									}
								});
							}
						});
						this.$forceUpdate();
					}
					
				});
			},	
			switchChange(e) {
				if (e.detail.value) {
					this.addressData.default = 1;
				} else {
					this.addressData.default = 0;
				}
			},
			btnClick() {
				this.$refs.wanlAddress.show()
			},
		
			//提交
			confirm() {
				let data = this.addressData;
				if (!data.name) {
					this.$wanlshop.msg('请填写姓名');
					return;
				}
				if (!/^1[0-9]{10,10}$/.test(data.mobile)) { // 1.0.2升级
					this.$wanlshop.msg('请输入正确的手机号码');
					return;
				}
				if (!this.image1 || !this.image2) {
					this.$wanlshop.msg('请上传身份证照片');
					return;
				}
				this.$api.post({
					url: '/wanlshop/agent/submitAgent',
					data: {
						name: data.name,
						phone: data.mobile,
						card_front: this.image1,
						card_back: this.image2,
					},
					success: res => {
						this.$wanlshop.msg('申请成功')
						uni.navigateTo({
							url: '/pages/user',
							});
						
					}
				});
				
			}
		}
	}
</script>

<style>
	.cu-form-group {
		padding: 0 25rpx;
	}

	.cu-form-group .title {
		min-width: calc(4em + 15px);
		font-size: 26rpx;
		font-weight: 600;
	}

	.cu-form-group input,
	.cu-form-group textarea {
		font-size: 26rpx;
	}

	.cu-btn.lg {
		font-size: 32rpx;
		height: 86rpx;
	}

	.tipsScroll {
		width: 100%;
		height: 500rpx;
		padding: 0 50rpx;
	}

	.tipsScroll .item {
		margin: 25rpx 0;
	}

	.tipsScroll .item view {
		color: #B8B8B8;
		font-size: 22rpx;
	}

	.tipsScroll .item text {
		color: #333;
	}
</style>
